<?php
// +-------------------------------------------------------------------
// |
// +-------------------------------------------------------------------
// | Copyright (c) 2009-2016 All rights reserved.
// +-------------------------------------------------------------------
namespace Service\Api\V1;

class UserServiceOrderList
{
    public $login = true; //是否需要登录才能访问该接口
    public $title = "预约记录列表ok";
    public $group = '物业服务';
    public $desc = "";

    public $input = [
        'page_num' => 'int;label=分页;comment=默认为1',
        'page_size' => 'int;label=分页条数;comment=默认为5',
    ];

    public $output = [
        'page_num' => 'label=当前页码;',
        'page_size' => 'label=每页条数;',
        'page_count' => 'label=总条数;',
        'page_total' => 'label=总页数;',
        'list' => [
            [
                'id' => 'label=订单id;',
                'logo_img' => 'label=logo图;',
                'infor_title' => 'label=标题;',
                'type_name' => 'label=类型名称;',
                'create_time' => 'label=创建时间;',
                'booking_time' => 'label=预约时间;',
                'contact' => 'label=联系人;',
                'mobile' => 'label=联系电话;',
                'state' => 'label=订单类型：0提交 1待确认 2待指派 3已指派 4已完成 9已取消;',
            ]
        ]
    ];

    public function run($param, $uid)
    {
        $page_num = $param['page_num'] ?: 1;
        $page_size = $param['page_size'] ?: 10;

        $list = M('service_order')
            ->where([
                'uid' => $uid,
            ])
            ->order('id desc')->page($page_num, $page_size)
            ->select();
        foreach($list as &$item){
            $ret = M('service')->where(['id' => $item['service_id']])->find();
            $item['logo_img'] = $ret['logo_img'];
            $item['infor_title'] = $ret['infor_title'];
            $item['contact'] = $ret['contact'];
            $item['mobile'] = $ret['mobile'];
            $type_data = M('service_type')->where(['id' => $ret['service_type_id']])->find();
            $item['type_name'] = $type_data['name'];
        }
        $count = M('service_order')
            ->where([
                'uid' => $uid,
                'order_type' => ['in', '0,1,2,3,4'],
            ])->count();
        return [
            'list'=> $list,
            'page_count' => $count,
            'page_total' => ceil($count / $page_size)
        ];
    }
}
